(function($,window,undefined){
	/**外面全局的多语言资源类 **/
	var rss=window.rss; 
	
	/**外面的基础要的页面传来的参数**/
	var localInfo=window.localInfo;
	
	var twoStepVerify = "";  //二次认证
	var reqClientType = localInfo.reqClientType;
	var loginAccount = localInfo.loginUserName;
	var email = localInfo.email;
	var pageToken = localInfo.pageToken;
	var resetPasswdMode = localInfo.resetPasswdMode;
	
	var userInfo = {
		oldAccountType: "",
		oldUserAccount: "",
		oldAuthCode: "",
		newAccountType: "",
		newUserAccount: "",
		newAuthCode: ""
	};
	
	var authCodeLabel = '<div class="dbtn2 sbtn r" act="getVerificationCode"  intervaltime="60" id="getAuthCode1"><span>'+rss.getAuthCode+'</span><p id="get_authcode_error_info"></p></div>';
	
	
	$(document).on("click","#logoutAllBrowser",function(){
		// 调用后台接口，登出所有浏览器
		// 根据用户是否开启了账号，选择打开不同的弹出框
		if(localInfo.twoStepVerify=="1")
		{
			logoutAllBrowserDialog();
		}
		else
		{
			logoutAllBrowserDialogWithOutPWD();
		}
	});

	$(document).on("click","#setSecurityOption",function(){
		updateUI();
		setSecurityOption();
	});
	
	$(document).on("click","#twoVerifyBtn",function(e){
		e.stopPropagation();
		if(twoStepVerify == "") {
			twoStepVerify = localInfo.twoStepVerify;
		}
		if(twoStepVerify == '1') {
			switchOff();
		} else {
			switchOn();
		}
	});
	
	function logoutAllBrowserDialogWithOutPWD(){
		
		var html= '<span>' + rss.uc_logout_all_browser_content_withoutpwd + '</span>';
		// var html= html+ '<div class="dinput"><span><input id="password" type="password" placeholder="'+ rss.inputLingPwd +'"/></span></div>';
		var html= html + '<p id="error_info"></p>';
		
		$("<div/>").Dialog({
			title: rss.uc_logout_all_browser,
			titleUnderline: false,
			btnRight: {
				text: rss.iKnowBtn,
				fn: function() {
					
					var self = this;
					var password = "";
					logoutAllBrowser(password,function(){
						self.hide();
						showTipDialog(rss.uc_logout_all_browser_title, rss.close_btn, rss.uc_logout_all_browser_suc_content, function() {
							gotoUrl(localInfo.service);
						});
					});
				}
			},
			btnLeft: {
				text: rss.cancel_btn,
				fn: function() {
				}
			},
			html:html,
			beforeAction: function() {
			
			}
		}).Dialog('show');
		
	}
	
	// 登出所有浏览器
	function logoutAllBrowserDialog(){
		
		var html= '<span>' + rss.uc_logout_all_browser_content + '</span>';
		var html= html+ '<div class="dinput"><span><input id="password" type="password" placeholder="'+ rss.inputLingPwd +'"/></span></div>';
		var html= html + '<p id="error_info"></p>';
		
		
		$("<div/>").Dialog({
			title: rss.uc_logout_all_browser,
			titleUnderline: false,
			btnRight: {
				text: rss.iKnowBtn,
				fn: function() {
					
					var self = this;
					if (!ec.form.validator($("#password"), true))
					{
						return false;
					}
					var password = $("#password").val();
					logoutAllBrowser(password,function(){
						self.hide();
						showTipDialog(rss.uc_logout_all_browser_title, rss.close_btn, rss.uc_logout_all_browser_suc_content, function() {
							gotoUrl(localInfo.service);
						});
					});
				}
			},
			btnLeft: {
				text: rss.cancel_btn,
				fn: function() {
				}
			},
			html:html,
			beforeAction: function() {
				var self = this;
				self.disabled();
				$("#password").on("keyup change",function(){
					if ($("#password").val().trim() !="") {
						self.enable();
						return false;
					} else {
						self.disabled();
					}
				});
			}
		}).Dialog('show');
		checkPassword();
		
	}
	
	function showTipDialog(title, btnText, content, callback) {
		$("<div>").Dialog({
			title: title,
			btnRight: {
				text: btnText,
				fn: function() {
					this.hide();
					if (typeof callback == "function") {
						callback();
					}
				}
			},
			btnLeft: false,
			html: '<div class="center">' +
				'<img class="dimg" src="'+localInfo.successImgPath+'">' +
				'<p class="inptips2">' + content + '</p>' +
				'</div>'
		}).Dialog("show");
	}
	
	
	function logoutAllBrowser(password,callback)
	{
		var params = {
				reqClientType:localInfo.reqClientType,
				password:password,
				pageToken: pageToken
			};
			ajaxHandler("logoutAllBrowser", params, function(data) {
	 			if (data && data.isSuccess == 1) {
	 				callback();
	 			} else {
	 				
	 				// 70002003  忘记密码的错误码
	 				
	 				
	 				 if(errorCode == "10000004") 
					 {
						 showError($("#error_info"), rss.error_10000004);
					 }
	 				 else if(errorCode == "10000002") 
					 {
						 showError($("#error_info"), rss.error_10000002);
					 }
					 else 
					 {
						 showError($("#error_info"), rss.error_70001401);
					 }
	 			}
	 		}, function(){}, true, "json");
	}
	
	//设置安全选项
	function setSecurityOption() {
		$("<div/>").Dialog({
			title: rss.setSecOptions,
			titleUnderline: false,
			btnRight: {
				text: rss.next_btn,
				fn: function() {
					this.hide();
					var radioValue = $('#security-item').val();
					if(radioValue == '0') {
						this.hide();
						var emailActiveFlag = localInfo.emailActiveFlag;
						if(emailActiveFlag == 0) {//无验证邮箱
							identityAuth(1);
						}else {
							setSecurityEmail();
						}
					}else {
						setSecurityEmailAndPhone();
					}
				}
			},
			btnLeft: {
				text: rss.cancel_btn,
				fn: function() {
				}
			},
			html:'<div class="dcent"><input type="hidden" id="security-item" name="security-item"><div class="line">	<div class="mkcl"><b class="radio ron r" data-value="1" data-group="security-item"  id="r1" data-check="true"></b>	<p class="nodetit">'+rss.smsAndEmail+'</p></div>		<span class="inptips2">'+rss.sms+'</span>	<b class="btn-yes"></b>	<p class="inptips4">'+rss.secOptionPhoneTip+'</p>	<span class="inptips2">'+rss.mail+'</span>	<b class="btn-yes"></b>		<p class="inptips4">'+rss.secOptionEmailTip+'</p></div><div class="line">	<div class="mkcl">	<b class="radio roff r" data-value="0" data-group="security-item" id="r2" data-check=""></b>	<p class="nodetit">'+rss.emailOnly+'</p>		</div>	<span class="inptips2">'+rss.sms+'</span>	<b class="btn-no"></b>	<p class="inptips4">'+rss.secOptionTip+'</p>	<span class="inptips2">'+rss.mail+'</span>		<b class="btn-yes"></b>		<p class="inptips4">'+rss.secOptionAuthTip+'</p></div>	</div>',
			beforeAction: function() {
				if(resetPasswdMode == '0') {
					$("#r2").trigger("click");
				}
			}
		}).Dialog('show');
	}
	
	//验证身份
	function identityAuth(nextStepFlag) {
		$("<div/>").Dialog({
			title: rss.authentication,
			btnRight: {
				text: rss.next_btn,
				fn: function() {
					var self = this;
					userInfo.oldAuthCode = $("#authCode").val();
					if (!ec.form.validator($("#authCode"), true))
					{
						return false;
					}
					chkAuthCode(userInfo.oldAccountType, 3, userInfo.oldUserAccount, userInfo.oldAuthCode, function() {
						self.hide();
						$("div").Dialog({
							title: rss.secEmailAddr,
							btnRight: {
								text: rss.next_btn,
								fn: function() {
									var email = $("#security_email_input").val();
									var authCode = $("#authCode2").val();
									if (!ec.form.validator($("#security_email_input"), true))
									{
										return false;
									}
									if (!ec.form.validator($("#authCode2"), true))
									{
										return false;
									}
									var self = this;
									setPhoneEmail(2, 5, email, authCode, function() {
										self.hide();
										setSecurityEmail(email);  //设置安全邮箱弹框
									});
								}
							},
							btnLeft: {
								text: rss.cancel_btn,
								fn: function() {}
							},
							actions: {
								getVerificationCode: function() {
									var email = $("#security_email_input").val();
									if ($("#getAuthCode1").attr("disabled")) {
										return false;
									}
									if (!ec.form.validator($("#EmailDiv"), true)) {
				                        return false;
				                    }
									getAuthCode(1, email, 3, $("#getAuthCode1"));
								}
							},
							beforeAction: function() {
								var self = this;
								self.disabled();
								$("#authCode2").on("keyup change",function(){
									if ($("#authCode2").val().trim() !="" && $("#security_email_input").val().trim() !="") {
										self.enable();
										return false;
									} else {
										self.disabled();
									}
								});
								$("#security_email_input").on("keyup change",function(){
									if ($("#authCode2").val().trim() !="" && $("#security_email_input").val().trim() !="") {
										self.enable();
										return false;
									} else {
										self.disabled();
									}
								});
							},
							html: 
							'<div class="dinput" id="EmailDiv"><input id="security_email_input" type="text" placeholder="'+rss.inputNewSecEmail+'"></div><p id="email_error_info"></p>' + authCodeLabel + 
							'<div class="dinput sinput"><input id="authCode2" type="text" maxlength="8"  placeholder="'+rss.inputNewSecEmailAuthCode+'"></div><p id="oldAuthCode_error_info2"></p>' +
							'<div class="pop hidden">' +
							' <b class="uptick"></b>' +
							'</div>'
						}).Dialog('show');
						checkEmail();
						checkAuthCode2();
					});
				}
			},
			btnLeft: {
				text: rss.cancel_btn,
				fn: function() {}
			},
			actions: {
				getVerificationCode: function() {
					if ($("#getAuthCode1").attr("disabled")) {
						return false;
					}
					getAuthCode(userInfo.oldAccountType, userInfo.oldUserAccount, 3, $("#getAuthCode1"));
				}
			},
			beforeAction: function() {
				var self = this;
				self.disabled();
				$("#authCode").on("keyup change",function(){
					if ($("#authCode").val().trim() !="") {
						self.enable();
						return false;
					} else {
						self.disabled();
					}
				});
			},
			html: '<p class="inptips2">'+rss.setSecOptionTip+'</p><br>' +
			'<p class="inptips2"><span id="security_email_set_droplist">'+rss.verificationMode+'：' +getExpressPhone(userInfo.oldUserAccount)+ '</span></p>' + authCodeLabel  +
			'<input id="security_email_verify_input" type="hidden">' +
			'<div class="dinput" style="width:50%;"><input id="authCode" type="text" maxlength="8" placeholder="'+rss.inputAuthCodeTip+'"><p id="oldAuthCode_error_info"></p></div>'
		}).Dialog('show');
		checkAuthCode();
	}
	
	function authCodeCountDown(ele, text) {
		var authEle = ele.find("[act='getVerificationCode']");
		var disabled = authEle.attr("disabled");
		if (disabled) {
			return false;
		}
		authEle.addClass("auth_code_grey");
		jsInnerTimeout(authEle, text);
		return true;
	}
	
	function updateUI() {
		getUserAccInfo(loginAccount, function(data) {
			if (data.isSuccess == 1) {
				initUserInfo(data);
			}
		});
	}
	
	/* 保存帐号信息 */
	function initUserInfo(data) {
		userAcctInfoData = data;
		
		userInfo.oldAccountType = data.userAcctInfoList[0].accountType;
		userInfo.oldUserAccount = data.userAcctInfoList[0].userAccount;
	}
	
	function getUserAccInfo(userAccount, callback) {
		var params = {
			userAccount: userAccount,
			reqClientType: reqClientType,
			pageToken: pageToken
		};
		ajaxHandler("getUserAccInfo", params, function(data) {
 			if (data && data.isSuccess == 1) {
 				callback(data);
 			} else {
 				if(errorCode == "10000001") 
				 {
 					showError($("#setSecurityOption"), rss.error_10000001_3);
				 }else if(errorCode == "10000004") 
				 {
					 showError($("#setSecurityOption"), rss.error_10000004);
				 }else if(errorCode == "10000002") 
				 {
					 showError($("#setSecurityOption"), rss.error_10000002);
				 }
				 else 
				 {
					 showError($("#setSecurityOption"), rss.login_wrong);
				 }
 			}
 		}, function(){}, true, "json");
	}
	
	/* 设置安全邮箱或者安全手机 */
	function setPhoneEmail(opType, newAccountType, newUserAccount, newAuthCode, callback) {
		var params = {
			opType: opType,
			oldAccountType: 2,
			oldUserAccount: userInfo.oldUserAccount,
			oldAuthCode: userInfo.oldAuthCode,
			newAccountType: newAccountType,
			newUserAccount: newUserAccount,
			newAuthCode: newAuthCode,
 			reqClientType: reqClientType,
 			pageToken: pageToken
 		};
 		ajaxHandler("setPhoneEmail", params, function(data) {
 			if (data && data.isSuccess == 1) {
 				if (typeof callback == "function") {
 					callback();
 				}
 			} else {
				if (data.errorCode == "70001201" || data.errorCode == "10000001") {
					showError($(".errortip"), rss.error_70001201_1);
				}
				else if (data.errorCode == "70001401") {
					showError($(".errortip"), rss.error_70001401);
				}
				else if (data.errorCode == "70002001") {
					showError($(".errortip"), rss.error_70002001);
				}
				else if (data.errorCode == "70002055") {
					showError($(".errortip"), rss.error_70002055);
				}
				else if (data.errorCode == "70006006") {
					showError($(".errortip"), rss.error_70006006);
				}
				else if (data.errorCode == "70002002") {
					showError($(".errortip"), rss.error_70002002);
				}
				else if (data.errorCode == "70002003") {
					showError($(".errortip"), rss.error_70002003);
				}
				else if (data.errorCode == "70002057") {
					showError($(".errortip"), rss.error_70002057_0);
				}
				else if (data.errorCode == "70002058") {
					showError($(".errortip"), rss.error_70002058);
				}
				else if (data.errorCode == "70002039") {
					showError($(".errortip"), rss.error_70002039);
				}
				else if (data.errorCode == "70002016") {
					showError($(".errortip"), rss.error_70002016_1);
				}
				else if (data.errorCode == "10000002") {
					showError($(".errortip"), rss.error_10000002);
				}
				else if (data.errorCode == "70006007") {
					showError($(".errortip"), rss.error_70006007_1);
				}
				else if (data.errorCode == "10000004") {
					showError($(".errortip"), rss.error_10000004);
				}else {
					showError($(".errortip"), rss.setSecAccountFailed);
				}
					
			}
 		}, function(){}, true, "json");
	}
	
	//校验密码接口
	function verifyPassword(userAccount, accountType, password, callback) {
		var strParms="verifyPassword";
		var dataParms = "";
		dataParms={
			"userAccount":userAccount,
			"accountType":accountType,
			"password":password,
			"reqClientType":localInfo.reqClientType,
			"pageToken":pageToken
		};	
		ajaxHandler(strParms,dataParms,function(data){
			var strResult=data.isSuccess;
			if(strResult=="1")
			{
				callback();
			}
			else
			{
				var errorCode = data.errorCode;
				if(errorCode == '70002003'){
					showError($(".errortip"), rss.error_10000001_2);
				}else if(errorCode == '10002073'){
					showError($(".errortip"), rss.error_10002073);
				}else if(errorCode == '70002057'){
					showError($(".errortip"), rss.error_70002057_2);
				}else if(errorCode == '70002058'){
					showError($(".errortip"), rss.error_70002058_1);
				}else if(errorCode == '10000001'){
					showError($(".errortip"), rss.error_10000001_2);
				} else {
					showError($(".errortip"), rss.error_70002003);
				}
			}
		},function(){
		},true,"json");
	}
	
	//设置安全选项接口
	function resetPasswdModeInter(password) {
		var strParms="resetPasswdMode";
		var dataParms = "";
		if(password != "") {
			dataParms={
				"opFlag":"1",
				"opType":"1", //手机和邮箱
				"password":password,
				"reqClientType":localInfo.reqClientType,
				"pageToken":pageToken
			};	
		} else {
			dataParms={
				"opFlag":"1",
				"opType":"0",  //仅邮箱
				"reqClientType":localInfo.reqClientType,
				"pageToken":pageToken
			};	
		}
		ajaxHandler(strParms,dataParms,function(data){
			var opType = dataParms.opType;
			var strResult=data.isSuccess;
			if(strResult=="1")
			{
				$('<div>').Dialog({
					title: rss.hint,
	 				btnRight: {
	 					text: rss.ok,
	 					fn: function() {
	 						this.hide();
	 						window.location.reload();
	 					}
	 				},
	 				btnLeft: false,
	 				html:'<div class="center">'+
					'<img class="dimg" src=' + localInfo.sucPath + '>' +
					'<p class="inptips2">'+rss.setSecOptionSuccess+'</p></div>'
				}).Dialog('show');
		
				resetPasswdMode = opType;  //重新过设置resetPasswdMode，避免再次去刷新页面
				if(opType == "0") {
					localInfo.emailActiveFlag = "1";  //1表示现在有验证邮箱
				}
			}
			else
			{
				switch(data.errorCode) 
				{
					case '10000001':
					{
						$('<div>').Dialog({
							title: rss.hint,
			 				btnRight: {
			 					text: rss.ok,
			 					fn: function() {
			 						this.hide();
			 					}
			 				},
			 				btnLeft: false,
			 				html:'<div class="center">'+
							'<img class="dimg" src=' + localInfo.failedPath + '>' +
							'<p class="inptips2">'+rss.error_10000001+'</p></div>'
						}).Dialog('show');
						break;
					}
					case '10000004':
					{
						$('<div>').Dialog({
							title: rss.hint,
							btnRight: {
								text: rss.ok,
								fn: function() {
									this.hide();
								}
							},
							btnLeft: false,
							html:'<div class="center">'+
							'<img class="dimg" src=' + localInfo.failedPath + '>' +
							'<p class="inptips2">'+rss.error_10000004+'</p></div>'
						}).Dialog('show');
						break;
					}
					case '10000002':
					{
						$('<div>').Dialog({
							title: rss.hint,
							btnRight: {
								text: rss.ok,
								fn: function() {
									this.hide();
								}
							},
							btnLeft: false,
							html:'<div class="center">'+
							'<img class="dimg" src=' + localInfo.failedPath + '>' +
							'<p class="inptips2">'+rss.error_10000002+'</p></div>'
						}).Dialog('show');
						break;
					}
					case '10002073':
					{
						$('<div>').Dialog({
							title: rss.hint,
							btnRight: {
								text: rss.ok,
								fn: function() {
									this.hide();
								}
							},
							btnLeft: false,
							html:'<div class="center">'+
							'<img class="dimg" src=' + localInfo.failedPath + '>' +
							'<p class="inptips2">'+rss.error_10002073+'</p></div>'
						}).Dialog('show');
						break;
					}
					case '70002003':
					{
						$('<div>').Dialog({
							title: rss.hint,
							btnRight: {
								text: rss.ok,
								fn: function() {
									this.hide();
								}
							},
							btnLeft: false,
							html:'<div class="center">'+
							'<img class="dimg" src=' + localInfo.failedPath + '>' +
							'<p class="inptips2">'+rss.error_70002003+'</p></div>'
						}).Dialog('show');
						break;
					}
					case '10000302':
					{
						$('<div>').Dialog({
							title: rss.hint,
							btnRight: {
								text: rss.ok,
								fn: function() {
									this.hide();
								}
							},
							btnLeft: false,
							html:'<div class="center">'+
							'<img class="dimg" src=' + localInfo.failedPath + '>' +
							'<p class="inptips2">'+rss.error_10000302+'</p></div>'
						}).Dialog('show');
						break;
					}
					default: {
						$('<div>').Dialog({
							title: rss.hint,
							btnRight: {
								text: rss.ok,
								fn: function() {
									this.hide();
								}
							},
							btnLeft: false,
							html:'<div class="center">'+
							'<img class="dimg" src=' + localInfo.failedPath + '>' +
							'<p class="inptips2">'+rss.setSecOptionFailed+'</p></div>'
						}).Dialog('show');
	 					break;
	 				}
				}
			}
		},function(){
		},true,"json");
	}
	
	if(email == "") {
		email = rss.modifyUserInfo_no_bind;
	}
	if(localInfo.securityEmail == "") {
		localInfo.securityEmail = rss.modifyUserInfo_no_bind;
	}

	/* 设置安全选项仅通过邮箱 */
	function setSecurityEmail(emailTemp){
		if(emailTemp!=undefined && emailTemp!=null && emailTemp != "") {
			localInfo.securityEmail = emailTemp;
		}
		$("<div/>").Dialog({
			title: rss.hint,
			btnRight: {
				text: rss.set,
				fn: function() {
					this.hide();
					resetPasswdModeInter("");
				}
			},
			btnLeft: {
				text: rss.cancel_btn,
				fn: function() {}
			},
			html: '<span>'+rss.mailOnlyTip+'</span><br><span>'+rss.mail_addr_colon_space + email +"</span><br><span>"+rss.secEmailAddr_colon_space + localInfo.securityEmail + '</span><br><p id="error_info"></p>'
		}).Dialog('show');
	}
	
	if(localInfo.phone == "") {
		localInfo.phone = rss.modifyUserInfo_no_bind;
	}
	if(localInfo.securityPhone == "") {
		localInfo.securityPhone = rss.modifyUserInfo_no_bind;
	}
	if(localInfo.email == "") {
		localInfo.email = rss.modifyUserInfo_no_bind;
	}
	if(localInfo.securityEmail == "") {
		localInfo.securityEmail = rss.modifyUserInfo_no_bind;
	}
	var EmailAndPhoneHtml = "<span>"+rss.mailAndPhoneTip+"</span><br><span>"+rss.phoneNumberColonSpace+ getExpressPhone(localInfo.phone) +"</span><br><span>"+rss.secPhoneColonSpace + getExpressPhone(localInfo.securityPhone) +
							"</span><br><span>"+rss.mail_addr_colon_space + localInfo.email +"</span><br><span>"+rss.secEmailAddr_colon_space + localInfo.securityEmail + "</span><br><p id='error_info'></p>";
	
	/* 设置安全选项通过邮箱和手机 */
	function setSecurityEmailAndPhone() {
		$("<div/>").Dialog({
			title: rss.setSecOptionNeedAuth,
			btnRight: {
				text: rss.next_btn,
				fn: function() {
					var self = this;
					if (!ec.form.validator($("#password"), true))
					{
						return false;
					}
					$("#hidPassword").val($("#password").val());
					verifyPassword(localInfo.loginName, localInfo.accountType, $("#password").val(), function()  {
						self.hide();
						/* 设置安全选项通过邮箱和手机弹窗 */
						$('<div>').Dialog({
							title: rss.hint,
							btnRight: {
								text: rss.set,
								fn: function() {
									this.hide();
									var password = $("#hidPassword").val();
									resetPasswdModeInter(password);
								}
							},
							btnLeft: {
								text: rss.cancel_btn,
								fn: function() {}
							},
							html: EmailAndPhoneHtml
						}).Dialog('show');
					});
				}
			},
			btnLeft: {
				text: rss.cancel_btn,
				fn: function() {}
			},
			html: '<span>'+rss.huaweiAccount_colon_space+getExpressPhone(localInfo.userAccount)+'</span><div class="dinput"><span><input id="password" type="password" placeholder="'+rss.inputLingPwd+'"></span></div><p id="error_info"></p>',
			beforeAction: function() {
				var self = this;
				self.disabled();
				$("#password").on("keyup change",function(){
					if ($("#password").val().trim() !="") {
						self.enable();
						return false;
					} else {
						self.disabled();
					}
				});
			}
		}).Dialog('show');
		checkPassword();
	}
	
	
	
	
	/* 获取验证码 */
	function getAuthCode(accountType, account, type, $btn) {
		var params = {};
		var method = "";
		if (accountType == 1 || accountType == 5) {
			method = "getEMailAuthCode";
			params = {
	 			email: account,
	 			accountType: accountType,
	 			emailReqType: type,
	 			reqClientType: reqClientType,
	 			pageToken: pageToken,
	 			languageCode:localInfo.lang
	 		};
		} else if (accountType == 2 || accountType == 6) {
			method = "getSMSAuthCode";
			params = {
 				accountType: accountType,
 				userAccount: account,
 				reqClientType: reqClientType,
 				mobilePhone: account,
 				smsReqType:type,
 				pageToken: pageToken,
 				languageCode:localInfo.lang
 			};
		}
		
 		ajaxHandler(method, params, function(data) {

 			if (data && data.isSuccess == 1) {
 				$btn.attr("disabled");
 				if (method == "getSMSAuthCode") {
 					showSuccess($("#get_authcode_error_info"), rss.phoneMegHasSendTo.format(getExpressPhone(account)), "right", -1, 30);
 				} else if (method == "getEMailAuthCode") {
 					showSuccess($("#get_authcode_error_info"), rss.emialHasSendTo.format(account), "right", -1, 30);
 					$(".userAccount").html(account);
 				}
 				$btn.addClass("auth_code_grey");
 				jsInnerTimeout($btn, rss.resend);
 			} else {
 				$btn.removeAttr("disabled");
 				switch(data.errorCode) {
 					case '10000001':
 					case '10000003':
 					case '70001201': {
	 					showError($("#get_authcode_error_info"), rss.error_10000001);
	 					break;
	 				}
 					case '70001401': {
	 					showError($("#get_authcode_error_info"), rss.error_70001401);
	 					break;
	 				}
 					case '70002001': {
	 					showError($("#get_authcode_error_info"), rss.error_70002001);
	 					break;
	 				}
 					case '70002002': {
	 					showError($("#get_authcode_error_info"), rss.error_70002002);
	 					break;
	 				}
 					case '70002028': {
	 					showError($("#get_authcode_error_info"), rss.error_70002028);
	 					break;
	 				}
 					case '70002046': {
	 					showError($("#get_authcode_error_info"), rss.error_70002046);
	 					break;
	 				}
 					case '70002030': {
	 					showError($("#get_authcode_error_info"), rss.error_70002030);
	 					break;
	 				}
 					case '70001102': {
	 					if (method == "getEMailAuthCode") {
	 						showError($("#get_authcode_error_info"), rss.error_70001102_0);
	 					} else if (method == "getSMSAuthCode") {
	 						showError($("#get_authcode_error_info"), rss.error_70001102_1);
	 					}
	 					break;
	 				}
 					case '70001104': {
	 					if (method == "getEMailAuthCode") {
	 						showError($("#get_authcode_error_info"), rss.error_70001104_0, "left");
	 					} else if (method == "getSMSAuthCode") {
	 						showError($("#get_authcode_error_info"), rss.error_70001104_1, "left");
	 					}
	 					break;
	 				}
 					case '10000004': {
	 					showError($("#get_authcode_error_info"), rss.error_10000004);
	 					break;
	 				}
 					case '10000002': {
	 					showError($("#get_authcode_error_info"), rss.error_10000002);
	 					break;
	 				}
	 				default: {
	 					showError($("#get_authcode_error_info"), rss.getAuthCodeError);
	 					break;
	 				}
 				}
 			}
 		}, function(){}, true, "json");
 	}
	
	/* 检查验证码 */
	function chkAuthCode(accountType, authOprType, userAccount, authCode, callback) {
		var params = {
			accountType: accountType,
			userAccount: userAccount,
			authCode: authCode,
			authOprType: authOprType,
 			reqClientType: reqClientType,
			pageToken: pageToken
 		};
 		ajaxHandler("chkAuthCode", params, function(data) {
 			if (data && data.isSuccess == 1) {
 				callback();
 			} else {
 				switch(data.errorCode) 
 				{
	 				case '10000002':
 					{
	 					showError($("#oldAuthCode_error_info"), rss.error_10000002);
	 					break;
 					}
	 				case '10000001':
	 				case '70001201':
	 				{
	 					showError($("#oldAuthCode_error_info"), rss.error_10000001);
	 					break;
	 				}
	 				case '70001401':
	 				{
	 					showError($("#oldAuthCode_error_info"), rss.error_70001401);
	 					break;
	 				}
	 				case '70002039':
	 				{
	 					showError($("#oldAuthCode_error_info"), rss.error_70002039);
	 					break;
	 				}
	 				case '70002057':
	 				{
	 					showError($("#oldAuthCode_error_info"), rss.error_70002057_0);
	 					break;
	 				}
	 				case '70002058':
	 				{
	 					showError($("#oldAuthCode_error_info"), rss.error_70002058);
	 					break;
	 				}
	 				case '10000004':
	 				{
	 					showError($("#oldAuthCode_error_info"), rss.error_10000004);
	 					break;
	 				}
	 				default:
	 				{
	 					showError($("#oldAuthCode_error_info"), rss.authCodeError);
	 					break;
	 				}
 				}
 			}
 		}, function(){}, true, "json");
	}
	
	//关闭帐号保护
	function switchOff() {
		$("<div>").Dialog(
			{
				title: rss.closeAccountProtectTip,
				btnRight: {
					text: rss.ok,
					fn: function() {
						var self = this;
						if (!ec.form.validator($("#password"), true))
						{
							return false;
						}
						var password = $("#password").val();
						var dataParms={
								opType:"0",
								password:password,
								reqClientType:localInfo.reqClientType,
								pageToken:pageToken
						};
						ajaxHandler("setAcctProtect",dataParms,function(data){
							if("1"==data.isSuccess)
							{
								self.hide();
								$("#twoVerifyBtn").removeClass("on");
								twoStepVerify = '0';
								localInfo.twoStepVerify="0";
							}
							else
							{
								var errorCode = data.errorCode;
								if(errorCode == '10000001'){
									showError($(".errortip"), rss.error_10000001_2);
								}else if(errorCode == '10002073'){
										showError($(".errortip"), rss.error_10002073);
								}else if(errorCode == '70002057'){
									showError($(".errortip"), rss.error_70002057_2);
								}else if(errorCode == '70002058'){
									showError($(".errortip"), rss.error_70002058_1);
								}else if(errorCode == '70002003'){
									showError($(".errortip"), rss.error_10000001_2);
								} else {
									showError($(".errortip"), rss.error_70002003);
								}
							}
						},function(data){
						},false,"JSON");
					}
				},
				btnLeft: {
					text: rss.cancel_btn,
					fn: function() {}
				},
				html: '<span>'+ '<a class="accountDesDDirection">' + rss.huaweiAccount_colon_space + '</a>' + '<a class="accountDoubleDirection">' + getExpressPhone(localInfo.thirdBindPhoneOrEmailAccount) + '</a>' +'</span><div class="dinput"><span><input id="password" type="password" placeholder="'+rss.login_js_password+'"/></span></div><p id="error_info"></p>',
				beforeAction: function() {
					var self = this;
					self.disabled();
					$("#password").on("keyup change",function(){
						if ($("#password").val().trim() !="") {
							self.enable();
							return false;
						} else {
							self.disabled();
						}
					});
				}
		}).Dialog('show');
		checkPassword();
	}
	
	//开启帐号保护
	function switchOn() {
		var dataParms={
				opType:"1",
				reqClientType:localInfo.reqClientType,
				pageToken: pageToken
		};
		ajaxHandler("setAcctProtect",dataParms,function(data){
			if("1"==data.isSuccess)
			{
				$("#twoVerifyBtn").addClass("on");
				twoStepVerify = '1';
				localInfo.twoStepVerify="1";
			}
			else
			{
				var errorCode = data.errorCode;
				if(errorCode == '10000701')
				{
					$("<div/>").Dialog({
		 				title: rss.hint,
		 				btnRight: {
		 					text: rss.ok,
		 					fn: function() {
		 						this.hide();
			 					$("<div/>").Dialog({
									title: rss.userAgreement,
									btnRight: {
										text: rss.next_btn,
										fn: function() {
											this.hide();
											//下面是绑定账户
										}
									},
									btnLeft: {
					 					text: rss.cancel_btn,
					 					fn: function() {}
					 				},
									html: '<div class="dcent"><div class="line protocol"><p class="inptips6 mbottom">'+rss.privacyPolicy+'：<a class="more" href="">'+rss.moreDetails+'</a></p><p class="inptips2">'+rss.privacyPolicyTip1+'</p><p class="inptips2 mtop"><b data-value="true" class="tick"></b>'+rss.IAgree+'</p></div><div class="line protocol">	<p class="inptips6 mbottom">'+rss.userLicense+'：<a class="more" href="">'+rss.moreDetails+'</a></p>	<p class="inptips2">'+rss.privacyPolicyTip2+'</p>	<p class="inptips2 mtop"><b data-value="true" class="tick"></b>'+rss.IAgree+'</p></div>	</div>'
								}).Dialog('show');
		 					}
		 				},
		 				btnLeft: {
		 					text: rss.cancel_btn,
		 					fn: function() {}
		 				},
		 				html: '<div class="center"><span class="inptips2">'+rss.perfectInformationTip+'</span></div>'
		 			}).Dialog('show');
				}else if(errorCode == '10000702'){//邮箱未验证&未绑定手机，进入验证邮箱流程
					$('<div>').Dialog({
						title: rss.hint,
		 				btnRight: {
		 					text: rss.nowVerify,
		 					fn: function() {
		 						this.hide();
		 						verifyEmail2(localInfo.userAccount,localInfo.reqClientType);
		 					}
		 				},
		 				btnLeft: {
		 					text: rss.cancel_btn,
		 					fn: function() {}
		 				},
		 				html:'<div class="center">'+
						'<p class="inptips2">'+rss.unverifiedTip+'</p></div>'
					}).Dialog('show');
				} else if(errorCode == '10000703'){
					$('<div>').Dialog({
						title: rss.hint,
		 				btnRight: {
		 					text: rss.IGetIt,
		 					fn: function() {
		 						this.hide();
		 					}
		 				},
		 				btnLeft: false,
		 				html:'<div class="center">'+
						'<p class="inptips2">'+rss.setSecOptionTip2+'</p></div>'
					}).Dialog('show');
				} else if(errorCode == '70002003'){
					showError($("#twoVerifyBtn"), rss.error_70002003);
				} else {
					showError($("#twoVerifyBtn"), rss.systemBusy);
				}
			}
			
		},function(data){
		},false,"JSON");
	}
	
	/**
	 * 仅是调用getActivateEMailURL接口
	 */
	function verifyEmailInter(userAccount,reqClientType) {
		var param = {
				accountType:1,
				userAccount:userAccount,
				reqClientType:reqClientType,
				email:userAccount,
				pageToken:pageToken
		};
		ajaxHandler("getActivateEMailURL", param, function(data) {
 			if (data && data.isSuccess == 1) {
 				callback(data);
 			}else {
 				if (data.errorCode == "10000001" || data.errorCode == "70001201")
				{
					showError($("#error_info"), rss.error_10000001);
				}
				if (data.errorCode == "10000002")
				{
					showError($("#error_info"), rss.error_10000002);
				}
				if (data.errorCode == "10000004")
				{
					showError($("#error_info"), rss.error_10000004);
				}
				if (data.errorCode == "70002001")
				{
					showError($("#error_info"), rss.error_70002001);
				}
				if (data.errorCode == "70001401")
				{
					showError($("#error_info"), rss.error_70001401);
				}
				if (data.errorCode == "70002008")
				{
					showError($("#error_info"), rss.error_70002008);
				}
				if (data.errorCode == "70001102")
				{
					showError($("#error_info"), rss.error_70001102_2);
				}
				if (data.errorCode == "70001104")
				{
					showError($("#error_info"), rss.error_70001104_3);
				}
				if (data.errorCode == "70002019")
				{
					showError($("#error_info"), rss.error_70002019);
				}
				if (data.errorCode == "70002009")
				{
					showError($("#error_info"), rss.error_70002009);
				}
				else
				{
					showError($("#error_info"), rss.emailActivedFailed);
				}
 			}
 		}, function(){}, true, "json");
	}
	
	function getAccountInfo(userAcct,isGetAll,callback) {
		var dataParms = {
			"userAccount": userAcct,
			"reqClientType": localInfo.reqClientType,
			"isGetAll":isGetAll,
			"pageToken":localInfo.pageToken
		};
		ajaxHandler("getUserAccInfo", dataParms, function(data) {
			var isSuccess = data.isSuccess;
			if (isSuccess == '1') {
				callback(data);
			}
		}, function() {}, false, "json");
	}

	function isActiveAccount(userAccount)
	{
		var isExist = false;
		getAccountInfo(userAccount,1,function(data){
			if (data && data.isSuccess==1) {
				var datas = data.userAcctInfoList;
				for (var i=0;i<datas.length;i++) {
					var account = datas[i];
					if ((account.accountType == 1 || account.accountType == 2) && account.accountState == 1) {
						isExist = true;
						break;
					}
				}
			}
	   });
		return isExist;
	}
	
	/**
	 * 调用getActivateEMailURL接口并作弹窗
	 */
	function verifyEmail2(userAccount,reqClientType) {
		var param = {
				accountType:1,
				userAccount:userAccount,
				reqClientType:reqClientType,
				email:userAccount,
				pageToken:pageToken
		};
		ajaxHandler("getActivateEMailURL", param,
				function(data) {
					var flag = data.isSuccess;
					if (flag == "1") {	
						$("<div/>").Dialog({
			 				title: rss.varityEmailAddr,
			 				btnRight: {
			 					text: rss.verified,
			 					fn: function() {
			 						if (isActiveAccount(userAccount)) {
			 							 window.location.reload();
			 						} else {
			 							 showError($(".errortip"), rss.verifiedUnfinished);
			 						}
			 					}
			 				},
			 				btnLeft: {
			 					text: rss.cancel_btn,
			 					fn: function() {}
			 				},
			 				html:'<div class="etbar mkcl">	<img class="emcheckimg l" src="' +localInfo.emailCheckPng+ '">	<p class="inptips5 mbottom">' + rss.verifyEmailSendToOther.format(loginAccount) + '</p>	<p class="inptips1">'+rss.verifyEmailTip1+'</p>	<div class="midbtn"></div></div><div class="line">	<div class="ebbar"><p class="inptips1">'+rss.verifyEmailTip2+'</p><p class="inptips4">'+rss.verityEmailTip3+'</p><p class="inptips4">'+rss.verityEmailTip4+'</p><p class="inptips4">'+rss.verityEmailTip5+'</p><p class="inptips4">'+rss.verityEmailTip6+'<a class="resend" href="" act="action">'+rss.resend+'</a></p></div></div><p id="error_info"></p>',
			 				actions: {
								'action': function() {
									verifyEmailInter(userAccount,reqClientType);
								}
							}
			 			}).Dialog('show');
					} else {
						if (data.errorCode == "10000001" || data.errorCode == "70001201")
						{
							showError($("#error_info"), rss.error_10000001);
						}
						if (data.errorCode == "10000002")
						{
							showError($("#error_info"), rss.error_10000002);
						}
						if (data.errorCode == "10000004")
						{
							showError($("#error_info"), rss.error_10000004);
						}
						if (data.errorCode == "70002001")
						{
							showError($("#error_info"), rss.error_70002001);
						}
						if (data.errorCode == "70001401")
						{
							showError($("#error_info"), rss.error_70001401);
						}
						if (data.errorCode == "70002008")
						{
							showError($("#error_info"), rss.error_70002008);
						}
						if (data.errorCode == "70001102")
						{
							showError($("#error_info"), rss.error_70001102_2);
						}
						if (data.errorCode == "70001104")
						{
							showError($("#error_info"), rss.error_70001104_3);
						}
						if (data.errorCode == "70002019")
						{
							showError($("#error_info"), rss.error_70002019);
						}
						if (data.errorCode == "70002009")
						{
							showError($("#error_info"), rss.error_70002009);
						}
						else
						{
							showError($("#error_info"), rss.emailActivedFailed);
						}
						
					}
				},
				function(data) {
					showError($("#error_info"), rss.emailActivedFailed);
				},
				true, "json");
	}
	
	/* 密码检查 */
	function checkPassword() {
		var password = $("#password");
		ec.form.validator.bind(password, {
			type : [ "require"/*, "length"*/ ],
			trim : false,
			validOnChange : true,
			min : 6,
			max : 32,
			msg_ct : "#error_info",
			msg : {
				require : rss.js_inputpwd
//				length : rss.error_10000001_2
			},
			successFunction : function(data) {
				
			}
		});
	}
	
	function checkAuthCode() {
		var authCode = $("#authCode");
		ec.form.validator.bind(authCode, {
			type : ["require", "length", "int"],
            trim : false,
            min : 4,
            max : 8,
            validOnChange : true,
            msg_ct: "#oldAuthCode_error_info",
            msg : {
                require : rss.inputAuthCodeTip,
                length : rss.authCodeLength,
                int : rss.authCodeLength
            }
		});
	}
	
	function checkAuthCode2() {
		var authCode = $("#authCode2");
		ec.form.validator.bind(authCode, {
			type : ["require", "length", "int"],
            trim : false,
            min : 4,
            max : 8,
            validOnChange : true,
            msg_ct : "#oldAuthCode_error_info2",
            msg : {
                require : rss.inputAuthCodeTip,
                length : rss.authCodeLength,
                int : rss.authCodeLength
            }
		});
	}
	
	function checkEmail() {
		var newEmailAccount = $("#security_email_input");
		ec.form.validator.bind(newEmailAccount, {
			type: ["require", "email"],
			trim: false,
			validOnChange: true,
			msg_ct: "#email_error_info",
			msg: {
				require: '<span>'+rss.inputEmailAddr+'</span>',
				email: "<span>"+rss.validatorEmail+"</span>"

			}
		});
	}
	
})(jQuery,window);